package com.zzptc.easyshop.servlet;

import com.zzptc.easyshop.dao.UserDao;
import com.zzptc.easyshop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        PrintWriter pw = response.getWriter();//创建一个能写的对象
        pw.print("login succuful!");
        String username=request.getParameter("userName");
        String pwd=request.getParameter("password");
        Users users=new Users();
    users.setEu_user_name(username);
        users.setEu_password(pwd);

        UserDao ud=new UserDao();
        boolean i=false;
        try {
            i=ud.login(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(i){
            System.out.println("插入链接成功，请使用");
            //转发到登录界面   重新定义到新的界面
        }else {
            System.out.println("插入失败，请检查代码！");
        }
    }
}


       /* String username=request.getParameter("userName");   // 获取表单的userName的内容
        String pwd=request.getParameter("passWord");
        pw.print(username+" ,Welcome");        //打印在网页上
        Users users=new Users();
        users.setEu_user_name(username);
        users.setEu_password(pwd);
        UserDao ud=new UserDao();
        boolean i=false;
        try {
            i=ud.login(users);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        if(i){
            System.out.println("插入链接成功，请使用");
        }else {
            System.out.println("插入失败，请检查代码！");
        }*/


